@extends('admin.layout')
@section('content')
       <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                用户管理
                <small>列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 后台</a></li>
                <li><a href="#">用户管理</a></li>
                <li class="active">列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">快速查看用户列表</h3>
                        </div><!-- /.box-header -->
                                    
                       <div class='row'>
                        <form action='{{url('admin/user/menu')}}' method="get">
                          <div class='col-md-4'>
                                <div class='form-group'>
                                    <select name='num' class="form-control" >
                                        <option value='10' 
                                        @if(!empty($request['num'])&& ($request['num']==10))
                                           selected="selected"
                                        @endif
                                        >10</option>

                                        <option value='20' 
                                           @if(!empty($request['num'])&& ($request['num']==20))
                                              selected="selected"
                                           @endif
                                        >20</option>
                                        <option value='50'
                                          @if(!empty($request['num'])&& ($request['num']==50))
                                            selected="selected"
                                          @endif
                                        >50</option>
                                        <option value='100'
                                          @if(!empty($request['num'])&& ($request['num']==100))
                                            selected="selected"
                                          @endif
                                        >100</option>
                                       
                                    </select>
                                </div>    
                           </div>
                         <div class='col-md-6 col-md-offset-2'>
                          <div class="input-group input-group-sm">
                                <input class="form-control" type="text" name='keyword' value=
                                  {{$request['keyword'] or ''}}
                                >
                                 <span class="input-group-btn">
                                   <button class="btn btn-info btn-flat" >搜索</button>
                                 </span>
                          </div>
                         </div>
                         </form>
                       </div> 
                        <div class="box-body" >

                            @if(session('info'))
                             <div id='tishixiaoshi' class="alert alert-success alert-dismissable">
                             <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                            <h4><i class="icon fa fa-check"></i> 提示!</h4>
                             {{ session('info')}}
                        </div>
                            @endif
                            <script type="text/javascript">
                            	window.onload = function()
                            	{
                            		$('#tishixiaoshi').hide(3000);
                            	}
                            </script>
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th> ID</th>
                                    <th>用户名</th>
                                    <th>邮箱</th>
                                    <th>手机号</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                           
                                   @foreach($data as $user)
                                <tr>
                                    <td>{{ $user -> id}}</td>
                                    <td class ='ajaxName'>{{ $user -> name}}
                                    </td>
                                    <td>{{ $user -> email}}</td>
                                    <td>{{ $user -> phone}}</td>
                                    <td><a href="{{url('admin/user/menu')}}/{{$user -> id}}">
                                    	@if($user->status==0)
                                    	   启用
                                    	@else
                                    	  禁用
                                    	@endif
                                    	</a>
                                    </td>
                                    <td> <a href="{{url('/admin/user/alter')}}/{{$user -> id}}">编辑</a> 
                                         <a href="{{url('/admin/user/delete')}}/{{$user -> id}}">删除</a>
                                    </td>
                                </tr>
                                 @endforeach
                  
                            </table>
                           

                                {!! $data -> appends($request) -> render() !!}
                                
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->

    </div><!-- /.content-wrapper -->
    <script type="text/javascript">

    	window.onload = function()
    	{
    		$.ajaxSetup({
               headers:{
               	  'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
               } 
    		});
    		//***********************************
        	$('.ajaxName').on('dblclick',double);
             

             //定义函数
             function double()

        		
        	 {
        		 //获取原来的id
        		  var td = $(this);
        		  var id = td.prev().html();

        		  //获取当前元素的输出
                  var ajaxName = td.html();

                  //命名一个INPUT表单
                  var inp = $('<input type = "text" />')  		     
        	      inp.val(ajaxName);//将当前的输出放入value值中
        	      //将表单放入td中
        	       td.html(inp);
                  //自动对焦
                  inp.select();

                  //失去焦点事件
                  inp.blur(function(){
                  	//获取新值
                  	var newName = inp.val();
                  	   if(ajaxName == newName)
                  	   {
                  	   	 alert('你脑子有病');
                  	   	 td.html(ajaxName);
                  	   	 return;
                  	   }
                  	//ajax发送
                       	$.post('/admin/user/ajaxName',{id:id,name:newName},
                       		function(data){
                            if(data == '1')
                            {
                              alert('用户名已经存在');
                              td.html(ajaxName);
                               
                            }else if(data == 0)
                            {
                            	td.html(newName);
                            }else{
                            	alert('用户名修改失败');
                            	td.html(ajaxName);
                            }

                       	},'json');
                       	td.dblclick(double);
                  });
                  //清除事件
                  td.unbind('dblclick');
             
             }
        	// //回车
        	// window.onkeydown = function(){
        	// 	//获取新值
        	// 	var id = $(this).prev().html();
        	// 	var newName = inp.val();
        	// 	alert(id);
        	// }
    	}
    </script>
    <!-- 分页-->

                        
@endsection